home *** CD-ROM | disk | FTP | other *** search
/ Kit PC World De Ampliacion De Windows 95 / Kit PC World de ampliacion de Windows 95.iso / clarion / gauge / gauge.z / CWSIEVE.CLW < prev    next >
Text File  |  1995-08-21  |  3KB  |  92 lines

  1. Sieve         PROGRAM
  2.  
  3.               INCLUDE('KEYCODES.CLW')
  4.               MAP
  5.                 RunSieve
  6.                 INCLUDE('DDE.CLW')
  7.               END
  8.  
  9. OneShot       BYTE(0)
  10. Channel       LONG(0)
  11. Start         LONG
  12. Stop          LONG
  13. Duration      REAL
  14. Cycles        SIGNED(4000)
  15. CyclesPerMin  STRING(10)
  16.  
  17. Window WINDOW('Clarion for Windows'),AT(,,158,97),CENTER,SYSTEM,GRAY
  18.          STRING('Sieve of Eratosthenes Performance Test'),AT(14,21,,)
  19.          STRING(@N9),AT(35,45,36,10),USE(CyclesPerMin)
  20.          STRING('Cycles / Minute'),AT(70,45,,)
  21.          BUTTON('&Run'),AT(35,70,,),USE(?Run)
  22.          BUTTON('E&xit'),AT(90,70,,),USE(?Exit)
  23.        END
  24.  
  25.  CODE
  26.  OPEN(Window)
  27.  Channel = DDESERVER('CWSieve')
  28.  ACCEPT
  29.    CASE EVENT()
  30.  
  31.    OF EVENT:DDEcommand
  32.      PRESSKEY(AltR)
  33.      OneShot = 1
  34.  
  35.    OF EVENT:Accepted
  36.      CASE FIELD()
  37.      OF ?Run
  38.        DO SieveTest
  39.        IF OneShot THEN RETURN.
  40.  
  41.      OF ?Exit
  42.        RETURN
  43.      END
  44.    END
  45.  END
  46.  DDECLOSE(Channel)
  47.  
  48. SieveTest ROUTINE
  49.   SETCURSOR(CURSOR:Wait)
  50.   DISABLE(?Run,?Exit)
  51.   CyclesPerMin = 0
  52.   DISPLAY
  53.   Start = CLOCK() 
  54.   LOOP UNTIL CLOCK() > Start.
  55.   Start = CLOCK()
  56.   RunSieve
  57.   Stop = CLOCK()
  58.   Duration = (Stop - Start) / 100                !Calculate time used
  59.   CyclesPerMin = Cycles * 60 / Duration          !Calculate cycles per minute
  60.   DISPLAY
  61.   SETCLIPBOARD(CyclesPerMin)
  62.   ENABLE(?Run,?Exit)
  63.   SETCURSOR(CURSOR:Arrow)
  64.  
  65.  
  66. RunSieve         PROCEDURE                       !Sieve of Eratosthenes
  67.  
  68. ArraySize        EQUATE(1000)                    !Array size
  69. Flag             BYTE,DIM(ArraySize)             !Array of flags
  70. Count            SIGNED                          !Number of primes
  71. Prime            SIGNED                          !Next prime
  72. I                SIGNED                          !Loop counter
  73. K                SIGNED                          !Step size
  74.  
  75.   CODE
  76.   LOOP Cycles TIMES                              !Do multiple iterations
  77.     Count = 0                                    !Clear prime counter
  78.     CLEAR(Flag,1)                                !Set all flags on
  79.     LOOP I = 1 TO ArraySize                      !Sift out the non-primes
  80.       IF Flag[I]                                 !  For flags that are on
  81.         Prime = I + I + 1                        !    Set the next prime
  82.         K = I + Prime                            !  Set step count
  83.         LOOP WHILE K <= ArraySize                !  Loop through remainder
  84.           Flag[K] = 0                            !    Turning off flags
  85.           K += Prime                             !    Jump to next step
  86.         END                                      !  End the loop
  87.         Count += 1                               !Increment prime counter
  88.       END                                        !  End the IF
  89.     END                                          !End the LOOP
  90.   END                                            !End the outside LOOP
  91.   RETURN                                         !Return to caller
  92.